A computer program (hereinafter simply referred to as a program) is made up as an aggregate of a plurality of functions (methods). When the program is compiled, a compiler allocates a register to each of the functions constituting the program, using the same register set. Accordingly, if the value of the register lives beyond a function call in a predetermined portion of the program, it is necessary that the value of the register is reserved temporarily in memory.
By the way, the registers provided by the CPU include volatile registers of which register values are not reserved if a function is executed, and non-volatile registers of which register values are reserved if a function is executed.
Thus, if the register value lives beyond a function call in a certain portion of the program, there are two methods for evacuating the register value as follows. One of the methods is a so-called caller-saved method for allocating variables to the volatile registers to save the register values before invoking of a function, and restore the registers after return, whereby the register values are saved and restored.
Another method is a so-called caller-saved method for allocating variables to the non-volatile registers to save the register values before the use of the registers and restore the register values after the use in the called function, whereby the register values are saved and restored.
Classification of the non-volatile register and the volatile register is defined by the supplier of the machine (CPU), as the calling convention for using the register. Accordingly, the developer of the software system must develop the system in conformance with this calling convention.
In the conventional system development, the volatile register was allocated to the variables that do not live across a function, and the non-volatile register was allocated to the variables that live across a function, in accordance with the convention for using the register established by the machine supplier. As a variation of implementation, there is a method for allocating the volatile registers to the variables living before and after the function, but is not considered to be rational except for the special situation where the non-volatile registers are not supplied.
In the case where there are a plurality of systems interlinkable by software, each system usually generates code in accordance with the calling convention of using the non-volatile register and the volatile register, as described in the paragraph of the prior art. This presupposes that the systems are interlinked or invoke functions from each other.
Herein, one of the interlinkable systems is a JIT (Just In Time) compiler, in the relationship between code generated by the JIT compiler and an external function for object generation, the code generated by the JIT compiler invokes the external function in usual cases, but the opposite case is very rare. In this case, the register treated as the non-volatile register in the external function is not necessarily saved within the JIT compiler. However, conventionally, the non-volatile registers defined by the machine supplier are employed directly as the non-volatile register stationarily in JIT, whereby the essentially unnecessary contents of the register were saved and restored.
As above described, the non-volatile registers are allocated to the variables living across a function. This is because there are a greater number of favorable code patterns by allocating the variables to the non-volatile registers rather than allocating the variables to the volatile registers. That is, if the variables living across the function are allocated to the volatile registers, the registers are saved and restored by the number of functions invoked while the variable is defined and used lastly in the worst case, whereas when the variables are allocated to the non-volatile registers, the registers are necessary to be saved and restored at most once outside the living duration of the variable. However, if there is any variable living across the function, the function may be rarely invoked. And with the conventional method, the variables are allocated to the non-volatile registers, whereby the contents of the registers before and after the living duration of variables were saved and restored almost uselessly.